<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/7 0007
 * Time: 19:19
 */

namespace App\Models\ActivityTrigger;

class ActivityTriggerRepository implements \App\Contracts\Repositories\ActivityTriggerRepository
{
    public function create(ActivityTrigger $activityTrigger)
    {
        if (!is_null($activityTrigger->id)) {
            throw new \Exception('duplicate id');
        }
        if ($activityTrigger->save()) {
            return $activityTrigger;
        }
        return null;
    }
    public function findByConditionsPage($condition, $sortArray=array(), $start = 0, $limit = 10)
    {
        $qb = ActivityTrigger::query()->where($condition)->limit($limit)->skip($start);
        if (!empty($sortArray)) {
            foreach ($sortArray as $sort) {
                $qb = $qb->orderBy($sort[0], $sort[1]);
            }
        }
        return $qb->get();
    }
    public function countByConditions($condition)
    {
        return ActivityTrigger::query()->where($condition)->count();
    }

    public function update($updates, $condition)
    {
        return ActivityTrigger::query()->where($condition)->update($updates);
    }

    public function deleteByIds($ids)
    {
        return ActivityTrigger::destroy($ids);
    }

    public function getActivityTriggerById($id)
    {
        return ActivityTrigger::query()->find($id)->toArray();
    }
}
